//
//  UIBarButtonItem+.swift
//  shanshanlol微博
//
//  Created by 叶竞泽 on 2017/1/11.
//  Copyright © 2017年 JingZe. All rights reserved.
//

import Foundation

extension UIBarButtonItem {
    
    
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: 按钮标题
    ///   - fontSize: 字体大小
    ///   - target: target description
    ///   - action: action description
    ///   - isBackButton: 是否是返回按钮,如果是就加上箭头
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        let button: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        if isBack {
            button.setImage(UIImage(named: "navigationbar_back_withtext"), for: .normal)
            button.setImage(UIImage(named: "navigationbar_back_withtext_highlighted"), for: .highlighted)
            button.sizeToFit()
        }
        button.addTarget(target, action: action, for: .touchUpInside)
        
        // 实例化UIBarButtonItem
        self.init(customView: button)
    }
    
}
